package com.cypher.encryptionanddecryption.watcher;

import android.app.DatePickerDialog;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;

/**
 * 日期对话框扩展
 */
public class ExpandDatePickerDialog extends DatePickerDialog {
    /**
     * 显示日期类型
     */
    public enum DateViewType {
        /**
         * 正常显示
         */
        DATE,
        /**
         * 只显示年份
         */
        YEAR,
        /**
         * 只显示分月
         */
        YEAR_MONTH,
    }
    public ExpandDatePickerDialog(Context context, OnDateSetListener callBack,
                           int year, int monthOfYear, int dayOfMonth, DateViewType dateViewType) {
        super(context, callBack, year, monthOfYear, dayOfMonth);

        switch (dateViewType) {
            case YEAR:
                ((ViewGroup) this.getDatePicker().getChildAt(0)).getChildAt(2).setVisibility(View.GONE);
                break;
            case YEAR_MONTH:
                ((ViewGroup) ((ViewGroup) this.getDatePicker().getChildAt(0))
                        .getChildAt(0)).getChildAt(2).setVisibility(View.GONE);
                break;
        }
    }
}
